package cn.it.http.controller;

import cn.it.http.entity.contrnller.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@Controller
@SessionAttributes(value = "user")//获取数据
public class Test {

    @RequestMapping("/mapTest")
    public String mapTest(Map<String,Object> map){
        User user = new User();
        user.setId(1);
        user.setName("老王头");
        map.put("user",user);
        return "index";
       /* return "mapTest";*/
    }

    @RequestMapping("/modelTest")
    public String modelTest(Model model){
        User user = new User();
        user.setId(2);
        user.setName("老李头");
        model.addAttribute("user",user);
        return "index";
    }


   /* @RequestMapping("/modelModelAndView1")
    public ModelAndView modelAndView(){
        ModelAndView modelAndView = new ModelAndView();
        User user = new User();
        user.setId(1);
        user.setName("老王头");
        modelAndView.addObject("user",user);
        modelAndView.setViewName("mapTest");
        return modelAndView;
    }*/
   /* @RequestMapping("requestTest")
   public String requestTest(HttpServletRequest request){
       User user = new User();
       user.setName("zhangsan");
       user.setId(1);
       request.setAttribute("user",user);
       return "index";

   }*/

   @RequestMapping("/moseTest")
   public String modeTest(){
       return "index";
   }
   @ModelAttribute
   public User getUser(){
       User user = new User();
       user.setId(1);
       user.setName("zhangsan");
       System.out.println("hahaha");
       return user;
   }
}
